package com.superzqb.asus.superzqbFragment.superzqbShopQrcode.image;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.superzqb.asus.superzqb.R;
import com.superzqb.asus.superzqbFragment.superzqbShopQrcode.image.ImageLoader.Type;

import java.util.List;

public class GridviewAdapter extends BaseAdapter {
	//private  LayoutInflater mInflater;
	private Context mContext;
	private List<String> mDatas;
	private  int mItemLayoutId;
	private String dirPath;
	public GridviewAdapter(Context context, List<String> mDatas, int itemLayoutId, String dirPath){
		this.mContext=context;
		this.mDatas=mDatas;
		this.mItemLayoutId=itemLayoutId;
		this.dirPath=dirPath;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return  (mDatas==null)?0:mDatas.size();  
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return mDatas.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		// TODO Auto-generated method stub
		u viewHolder=null;
		if(arg1==null){  
            //Log.d("MyBaseAdapter", "新建convertView,position="+position);
            arg1 = LayoutInflater.from(mContext).inflate(
            		mItemLayoutId, null);  
              
            viewHolder = new u();  
            viewHolder.i = (ImageView)arg1.findViewById(
                    R.id.id_item_image);
            arg1.setTag(viewHolder);  
        }else{  
            viewHolder = (u)arg1.getTag();  
            //Log.d("MyBaseAdapter", "旧的convertView,position="+position);
            
        }
		
		ImageLoader.getInstance(3,Type.LIFO).loadImage(dirPath+"/"+mDatas.get(arg0), viewHolder.i);
		return arg1;
	}
	class u{
		ImageView i;
	}

}
